﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using jnagr.Model;

public class BaseHttpHandlerNo : IHttpHandler, IRequiresSessionState
{
    public HttpRequest Request;
    public HttpResponse Response;
    public HttpSessionState Session;
    public HttpServerUtility Server;
    public HttpCookie Cookie;
    string virtualPath = jnagr.Common.ConfigHelper.GetConfigString("VirtualPath");
    public jnagr.BLL.SysLog bllLog = new jnagr.BLL.SysLog();
    public virtual void ProcessRequest(HttpContext context)
    {
        Request = context.Request;
        Response = context.Response;
        Session = context.Session;
        Server = context.Server;
    }
    /// <summary>
    /// 输出：{isOk:1,message:"操作成功"}
    /// </summary>
    public void WriteSuccess()
    {
        WriteMessage(1, "操作成功！");
    }
    /// <summary>
    /// 输出：{isOk:1,message:"操作成功"}
    /// </summary>
    /// <param name="ex">错误</param>
    public void WriteError(string message)
    {
        WriteMessage(0, message);
    }
    /// <summary>
    /// 输出：{isOk:1,message:"操作成功"}
    /// </summary>
    /// <param name="Status">0失败，1成功</param>
    /// <param name="Message">消息内容</param>
    public void WriteMessage(int Status, string Message)
    {
        Response.Write(jnagr.Common.JsonHelper.ToResultJson(Status, Message));
    }
    /// <summary>
    /// 输入日志
    /// </summary>
    /// <param name="Message"></param>
    public void WriteLog(string Message)
    {
        SysLog modelLog = new SysLog();
        modelLog.AddTime = DateTime.Now;
        modelLog.AddUserID = 2;
        modelLog.IP = Request.UserHostAddress;
        modelLog.Message = Message;
        modelLog.Page = Request.RawUrl;
        bllLog.Add(modelLog);
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
